import json


class Product:
    def __init__(self, name):
        self.name = name

    def get_name(self):
        return self.name


class ProductA(Product):

    def __init__(self, name):
        super().__init__(name)


class ProductB(Product):

    def __init__(self, name):
        super().__init__(name)


class ProductFactory:
    def __init__(self, config_file):
        self.config = self.load_config(config_file)

    @staticmethod
    def load_config(config_file):
        with open(config_file, 'r', encoding='utf-8') as f:
            return json.load(f)

    def create_product(self, name):
        product_type = self.config.get('product_type', 'default')
        if product_type == "A":
            return ProductA(name)

        elif product_type == "B":
            return ProductB(name)
        else:
            return Product(name)


# 使用对象工厂根据配置文件动态创建产品对象

product_factory = ProductFactory(config_file='config.json')
product_a = product_factory.create_product("Apple").get_name()
product_b = product_factory.create_product("Banana").get_name()

print(product_a)
print(product_b)
'''
Apple
Banana
'''